import QtQuick 1.1
import com.nokia.meego 1.0
import "Logic.js" as Logic

Page {
    id: pageSettings
    objectName: "pageSettings"
    orientationLock: appWindow.lockOrientation()

    tools: ToolBarLayout {
        visible: true
        ToolIcon { iconId: "toolbar-back"; onClicked: { pageStack.pop(); } }
    }

    onVisibleChanged: {
        if( visible ) {
            cppSettings.initSettings()
        }
    }

    //-------------------------

    function setButtonTextDataTimeFormat( value ) {
        pB_dateTimeFormat.text = value
    }

    function setButtonTextLanguage( value ) {
        pB_language.text = value
    }

    //-------------------------

    QNMTitle {
        id: titlePage
        text: qsTr("Settings") + cppLanguage.forceLanguage
        image: "./pictures/options.png"
    }

    BackgroundPage { }

        Flickable {
            id: qnm_flick_settings
            //anchors.fill: parent
            anchors {
                top: titlePage.bottom
                bottom: parent.bottom
                left: parent.left
                right: parent.right
                topMargin: 20
            }
            contentHeight: qnm_col_settings.height
            contentWidth: qnm_col_settings.width
            flickableDirection: Flickable.VerticalFlick

            Column {
                id: qnm_col_settings
                spacing: 20

                anchors.centerIn: parent
                width: qnm_flick_settings.width

                Component.onCompleted: {
                    var count = children.length;
                    for( var i = 0; i < count; i++) {
                        var item = children[i];
                        item.anchors.horizontalCenter = item.parent.horizontalCenter;
                    }
                }


                Label {
                    text: qsTr("Orientation:") + cppLanguage.forceLanguage
                }
                ButtonRow {
                    id: rowOrientation
                    exclusive: true
                    width: parent.width*0.8
                    height: 80
                    states: [
                        State {
                            name: "landscape"
                            when: ( pbOrLand.checked == true )
                            PropertyChanges { target: pbOrPort; opacity: 0.5; }
                            PropertyChanges { target: pbOrAuto; opacity: 0.5; }
                        },
                        State {
                            name: "portrait"
                            when: (pbOrPort.checked == true)
                            PropertyChanges { target: pbOrAuto; opacity: 0.5; }
                            PropertyChanges { target: pbOrLand; opacity: 0.5; }
                        },
                        State {
                            name: "auto"
                            when: (pbOrAuto.checked == true)
                            PropertyChanges { target: pbOrLand; opacity: 0.5; }
                            PropertyChanges { target: pbOrPort; opacity: 0.5; }
                        }
                    ]
                    transitions: Transition { NumberAnimation { properties: "opacity"; duration: 750 } }
                    Button {
                        height: 80
                        width: parent.width/3
                        id: pbOrAuto
                        text: qsTr("Auto") + cppLanguage.forceLanguage
                        onClicked: {
                            cppSettings.changeOrientation( "auto" )
                        }
                        checked: appWindow.lockOrientation() === PageOrientation.Automatic
                    }
                    Button {
                        height: 80
                        width: parent.width/3
                        id: pbOrLand
                        text: qsTr("Landscape") + cppLanguage.forceLanguage
                        onClicked: {
                            cppSettings.changeOrientation( "landscape" )
                        }
                        checked: appWindow.lockOrientation() === PageOrientation.LockLandscape
                    }
                    Button {
                        height: 80
                        width: parent.width/3
                        id: pbOrPort
                        text: qsTr("Portrait") + cppLanguage.forceLanguage
                        onClicked: {
                            cppSettings.changeOrientation( "portrait" )
                        }
                        checked: appWindow.lockOrientation() === PageOrientation.LockPortrait
                    }
                }


                Label {
                    text: qsTr("Theme:") + cppLanguage.forceLanguage
                }
                ButtonRow {
                    id: rowTheme
                    exclusive: true
                    width: parent.width*0.8
                    height: 80
                    states: [
                        State {
                            name: "white"
                            when: ( pbWhiteTheme.checked == true )
                            PropertyChanges { target: pbBlackTheme; opacity: 0.5; }
                        },
                        State {
                            name: "black"
                            when: (pbBlackTheme.checked == true)
                            PropertyChanges { target: pbWhiteTheme; opacity: 0.5; }
                        }
                    ]
                    transitions: Transition { NumberAnimation { properties: "opacity"; duration: 750 } }
                    Button {
                        height: 80
                        width: parent.width/2
                        id: pbWhiteTheme
                        text: qsTr("Light") + cppLanguage.forceLanguage
                        iconSource: "image://theme/icon-m-content-note-inverse"
                        onClicked: {
                            theme.inverted = false
                            cppSettings.changeTheme( "light" )
                        }
                        checked: !theme.inverted
                    }
                    Button {
                        height: 80
                        width: parent.width/2
                        id: pbBlackTheme
                        text: qsTr("Dark") + cppLanguage.forceLanguage
                        iconSource: "image://theme/icon-m-content-note"
                        onClicked: {
                            theme.inverted = true
                            cppSettings.changeTheme( "dark" )
                        }
                        checked: theme.inverted
                    }
                }

                Label {
                    text: qsTr("Language: ") + cppLanguage.forceLanguage
                }
                Button {
                    id: pB_language
                    width: parent.width*0.8
                    height: 80
                    text: ""
                    iconSource: theme.inverted === false ? "image://theme/icon-m-content-sms" : "image://theme/icon-m-content-sms-inverse"
                    onClicked: { qnm_cntxMenu_language.open() }
                }

                Label {
                    text: qsTr("Network interfaces") + ":" + cppLanguage.forceLanguage
                }
                Button {
                    id: pB_networkInterfaces
                    width: parent.width*0.8
                    height: 80
                    text: qsTr("Network interfaces") + cppLanguage.forceLanguage
                    iconSource: theme.inverted === false ? "pictures/icon-wlan.png" : "pictures/icon-wlan-inverse.png"
                    onClicked: {
                        Logic.openFile("DialogNetworkInterfaces.qml")
                        cppSettings.initOptionsIfaces()
                    }
                }
                //**********

                //**********

            } //Column
        } //Flickable


        //----------------------------------------------

        /*
        property string datetimeformat0: qsTr("YYYY-MM-DD HH:MM:SS")
        property string datetimeformat1: qsTr("MM-DD-YYYY HH:MM:SS")
        property string datetimeformat2: qsTr("DD-MM-YYYY HH:MM:SS")
        property string datetimeformat3: qsTr("DD.MM.YYYY HH:MM:SS")
        property string datetimeformat4: qsTr("MM.DD.YYYY HH:MM:SS")
        property string datetimeformat5: qsTr("YYYY.MM.DD HH:MM:SS")
        property string datetimeformat6: qsTr("DD/MM/YYYY HH:MM:SS")
        property string datetimeformat7: qsTr("MM/DD/YYYY HH:MM:SS")
        property string datetimeformat8: qsTr("YYYY/MM/DD HH:MM:SS")
        ContextMenu {
            id: qnm_cntxMenu_dateTimeFormat
            MenuLayout {
                MenuItem {
                    id: id_datetimeformat0
                    text: datetimeformat0
                    onClicked: {
                        pB_dateTimeFormat.text = datetimeformat0
                        cppSettings.changeFormatDT(0)
                    }
                }
                MenuItem {
                    id: id_datetimeformat1
                    text: datetimeformat1
                    onClicked: {
                        pB_dateTimeFormat.text = datetimeformat1
                        cppSettings.changeFormatDT(1)
                    }
                }
                MenuItem {
                    id: id_datetimeformat2
                    text: datetimeformat2
                    onClicked: {
                        pB_dateTimeFormat.text = datetimeformat2
                        cppSettings.changeFormatDT(2)
                    }
                }
                MenuItem {
                    id: id_datetimeformat3
                    text: datetimeformat3
                    onClicked: {
                        pB_dateTimeFormat.text = datetimeformat3
                        cppSettings.changeFormatDT(3)
                    }
                }
                MenuItem {
                    id: id_datetimeformat4
                    text: datetimeformat4
                    onClicked: {
                        pB_dateTimeFormat.text = datetimeformat4
                        cppSettings.changeFormatDT(4)
                    }
                }
                MenuItem {
                    id: id_datetimeformat5
                    text: datetimeformat5
                    onClicked: {
                        pB_dateTimeFormat.text = datetimeformat5
                        cppSettings.changeFormatDT(5)
                    }
                }
                MenuItem {
                    id: id_datetimeformat6
                    text: datetimeformat6
                    onClicked: {
                        pB_dateTimeFormat.text = datetimeformat6
                        cppSettings.changeFormatDT(6)
                    }
                }
                MenuItem {
                    id: id_datetimeformat7
                    text: datetimeformat7
                    onClicked: {
                        pB_dateTimeFormat.text = datetimeformat7
                        cppSettings.changeFormatDT(7)
                    }
                }
                MenuItem {
                    id: id_datetimeformat8
                    text: datetimeformat8
                    onClicked: {
                        pB_dateTimeFormat.text = datetimeformat8
                        cppSettings.changeFormatDT(8)
                    }
                }
            }
        }
        */


        property string lang_0: "Auto"
        property string lang_ru: "Russian"
        property string lang_en: "English"
        property string lang_hu: "Hungarian"
        ContextMenu {
            id: qnm_cntxMenu_language
            MenuLayout {
                MenuItem {
                    id: id_lang_0
                    objectName: "lang_0"
                    text: lang_0
                    onClicked: {
                        pB_language.text = lang_0
                        cppSettings.changeLanguage( 0 )
                        cppLanguage.selectLanguage("0")
                    }
                }
                MenuItem {
                    id: id_lang_en
                    //objectName: "lang_en"
                    text: lang_en
                    onClicked: {
                        pB_language.text = lang_en
                        cppSettings.changeLanguage( 1 )
                        cppLanguage.selectLanguage("en")
                    }
                }
                MenuItem {
                    id: id_lang_ru
                    //objectName: "lang_ru"
                    text: lang_ru
                    onClicked: {
                        pB_language.text = lang_ru
                        cppSettings.changeLanguage( 2 )
                        cppLanguage.selectLanguage("ru")
                    }
                }/*
                MenuItem {
                    id: id_lang_hu
                    text: lang_hu
                    onClicked: {
                        pB_language.text = lang_hu
                        cppSettings.changeLanguage( 3 )
                        cppLanguage.selectLanguage("hu")
                    }
                }*/
            }
        }

}
